<?php (defined('BASEPATH')) OR exit('No direct script access allowed');
class MY_Model extends Model {
    public  $table = "table";
    public  $id = "id";
    
    public function save($data) {
        $this->db->insert($this->table, $data);
    }
    public function new_id() {
        $id = $this->db->insert_id();
        return $id;
    }
    public function update($data) {
        $id = $data[$this->id];
        $this->db->where($this->id, $id);
        $this->db->update($this->table, $data);
    }

    public function delete($id) {
        $this->db->delete($this->table, array($this->id => $id));
    }

    public function get_all() {
        $query = "select * from $this->table";
        return $this->db->query($query)->result_array();
    }

    function get($id=0) {
        return $query = $this->db->get_where($this->table, array($this->id => $id))->row_array();
    }

    public function get_by_field($field='kategori', $filter='1') {
        $query = "select * from $this->table where $field='$filter'";
        return $this->db->query($query)->result_array();
    }
    public function get_by_fields($kriteria=array()) {
        return $this->db->get_where($this->table, $kriteria)->result_array();
    }
}